﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.OleDb;

namespace attendance.L1Dataaccess
{
    public class masterDB
    {
        public static readonly string connStr3 = "Provider = Microsoft.Jet.OLEDB.4.0 ;Data Source=" + HttpContext.Current.Server.MapPath("~/attendance.mdb") + "; Jet OLEDB:Database Password=";//);
        public static DataSet GetItem(string commandText)
        {
            OleDbConnection conn = new OleDbConnection(connStr3);
            DataSet ds = new DataSet();
            try
            {
                conn.Open();
                string sql = commandText;// "select * from word";
                OleDbDataAdapter myadapter = new OleDbDataAdapter(sql, conn);

                myadapter.Fill(ds);

            }
            catch (Exception ee)
            {
                DataTable dtMaster = new DataTable();//创建数据表 
                ds.Tables.Add(dtMaster);
                ds.Tables[0].Columns.Add();
                DataRow dr = ds.Tables[0].NewRow();
                dr[0] = "defaulqwesda6588";
                ds.Tables[0].Rows.Add(dr);
            }
            finally
            {
                conn.Close();                //关闭连接
                conn.Dispose();
                GC.SuppressFinalize(conn);
            }
            if (ds.Tables[0].Rows.Count == 0)
            {
                try
                {
                    DataRow drr = ds.Tables[0].NewRow();
                    drr[0] = "defaulqwesda6577";
                    ds.Tables[0].Rows.Add(drr);
                }
                catch
                {
                    DataRow drr = ds.Tables[0].NewRow();
                    drr[0] = -98685;
                    ds.Tables[0].Rows.Add(drr);
                }
            }
            return ds;


        }
        public static bool AddDeleteItem(string commandText)
        {
            bool bb = true;
            OleDbConnection conn = new OleDbConnection(connStr3);

            try
            {
                conn.Open();
                OleDbCommand cmd = new OleDbCommand(commandText, conn);
                cmd.ExecuteNonQuery();

            }

            catch (Exception ee)
            {
                bb = false;// return false;              //如果有错误，输出错误信息
            }
            finally
            {
                conn.Close();                //关闭连接
                conn.Dispose();
                GC.SuppressFinalize(conn);
            }

            return bb;

        }
    }
}